{% extends "admin/base.html" %}
{% block hscript %}
	<link rel="stylesheet" href="themes/{{site.theme}}/style/jquery.wysiwyg.css" type="text/css" media="screen" />
	<script type="text/javascript" src="themes/{{site.theme}}/style/jquery.min.js"></script>
    <script type="text/javascript" src="themes/{{site.theme}}/style/jquery.form.js"></script>
    <script type="text/javascript" src="themes/{{site.theme}}/style/jquery.wysiwyg.js"></script>
{% endblock %}
{% block nav %}
			<a href="?a=Post">All posts</a>
			{%if post %}<a href="?a=Post&d=create">Write post</a>{%endif%}
{% endblock %}
{% block content %}
<form id="postForm" action="?a=Post" method="post">
	 <div class="wrap">
      <h2>{%if post %}Edit Post{%else%}Write Post{%endif%}</h2>
      <div id="poststuff">

<div id="submitlink" class="submitbox">

<div id="previewview">
<h3>Date</h3>
<div class="inside">
<input type="text" name="date" value='{{post.date|date:"yyyy-MM-dd HH:mm:ss"}}' />
<br />yyyy-MM-dd HH:mm:ss
</div>
</div>
<h3>Category</h3>
<div class="inside">
<p style="height:120px;overflow-y:auto">
                    {%for cat in categories%}
                       <input type="checkbox" name="categories" tabindex="7" value="{{cat.id}}" {%if post.categoryIds|contain:cat.id %}checked="checked"{%endif%}/>{{cat.name}}<br>
                    {%endfor%}
</p>
</div>

<p class="submit">
	<input type="submit" tabindex="9" value="Save" name="save" class="button button-highlighted"/>&nbsp;
	<input type="checkbox" style="margin-left:10px;" tabindex="8" value="publish" name="publish" class="button button-highlighted" {%if post.published %}checked="checked"{%endif%}/>Published
</p>

</div>

<div id="post-body2">

<div id="titlediv">
<h3>Title</h3>
<div id="titlewrap">
	<input id="title" type="text" id="title" value="{{post.title}}" tabindex="1" size="60" name="title"/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Article</h3>
<div class="editorcontainer">
	<textarea id="article" style="width: 695px;" cols="40" rows="15" tabindex="2" name="article">{{post.article}}</textarea><br/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Slogan</h3>
<div class="inside">
	<input id="slogan" type="text" value="{{post.slogan}}" tabindex="3" size="40" name="slogan"/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Tags</h3>
<div class="inside">
	<input id="tags" type="text" value="{{post.tagNames}}" tabindex="4" size="40" name="tagNames"/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Excerpt</h3>
<div class="inside">
	<textarea id="excerpt" style="width: 675px;" cols="38" tabindex="5" name="excerpt">{{post.excerpt}}</textarea>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Reload</h3>
<div class="inside">
	<input id="source" type="text" value="{{post.source}}" tabindex="6" size="94" name="source"/><br/>
</div>
</div>

	<input type="hidden" value="{{post.id}}" name="id"/>
	<input type="hidden" name="d" value="{% if post %}update{% else %}add{% endif %}" />
</div>
</div>	
</div>
</form>
{% endblock  %}
{% block bscript %}    
<script type="text/javascript">
$(function(){
	var options = {
			css : '/themes/{{site.theme}}/style/style.css',
			//autoSave : true,
			//debug : true,
			controls : {
				strikeThrough : {visible : true},
				underline : { visible : true},
				separator00 : { visible : true },
				justifyLeft   : { visible : true},
	            justifyCenter : { visible : true},
	            justifyRight  : { visible : true},
	            justifyFull   : { visible : true},
	            separator01 : { visible : true },
	            indent  : { visible : true },
	            outdent : { visible : true },
	            subscript   : { visible : true },
	            superscript : { visible : true },
	            separator04 : { visible : true },
	            insertOrderedList    : { visible : true },
	            insertUnorderedList  : { visible : true },
	            insertHorizontalRule : { visible : true },
	            separator06 : { visible : true && !( $.browser.msie ) },
	            h1 : { visible : false },
	            h2 : { visible : false },
	            h3 : { visible : false },
	            html : { visible : true },
	            removeFormat : { visible : false },
	            par : { 
		            visible :true && $.browser.msie , 
		            className : 'undo',
	            	exec : function (){ this.editorDoc.execCommand('InsertParagraph', true);},
		            tags : ['p'] 
				},
			},
		};
	$('#article').wysiwyg(options);
	}
);

$(function() { 
    var options = {
    	    dataType: 'json',
    	    success : function(data) {
	    			var hmd = $("#hiddenMessage");
	    			if (data.type == "error") {
	    				hmd.html("<div class='error'>" + data.message + "</div>");
	    			} else {
	    				hmd.html("<div class='info'>" + data.message + "</div>");
	    				{% if post|not %}
	    				$("#title").val('');
	    				$("#slogan").val('');
	    				$("#article").val('');
	    				{% endif %} 
	    			}
	    			hmd.show().focus();
    			},
    	};
    	$("#postForm").ajaxForm(options);
    }
);
</script>
{% endblock %}